home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
001
/
piblist.arc
/
POSITION.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-03-28
|
7KB
|
188 lines
(*----------------------------------------------------------------------*)
(* Position -- parse positioning commands *)
(*----------------------------------------------------------------------*)
PROCEDURE Position( VAR legal: BOOLEAN );
(*----------------------------------------------------------------------*)
(* *)
(* Procedure: Position *)
(* *)
(* Purpose: Parses positioning commands. *)
(* *)
(* Calling sequence: *)
(* *)
(* Position( VAR legal : BOOLEAN ); *)
(* *)
(* legal --- returned TRUE if command was OK. *)
(* *)
(* Calls: MIN *)
(* RMAX *)
(* RMAX *)
(* Find_Line *)
(* Find_Page *)
(* Find_String *)
(* Skipbl *)
(* Number *)
(* *)
(*----------------------------------------------------------------------*)
VAR
c: CHAR;
n: REAL;
sn: INTEGER;
rel: BOOLEAN;
ow: INTEGER;
I: INTEGER;
BEGIN (* Position *)
(* Assume command is OK *)
legal := TRUE;
(* Look for initial number signalling *)
(* relative positioning *)
IF Command[Cind] IN ['+','-','0'..'9'] THEN
BEGIN
rel := TRUE;
(* Remember sign *)
sn := +1;
IF Command[Cind] IN ['+','-'] THEN
BEGIN
IF Command[Cind] = '-' THEN sn := -1;
Cind := Cind + 1;
END;
(* Pick up the number *)
Number( n );
n := sn * n;
(* Skip any blanks after number *)
Skipbl;
(* If no command follows, assume *)
(* 'S' = screen request *)
IF Command[Cind] = nul THEN
c := 'S'
ELSE (* Pick up command letter *)
BEGIN
c := Command[Cind];
Cind := Cind + 1;
IF c = '''' THEN (* Get search string *)
BEGIN
IF Command[Cind] <> Nul THEN
BEGIN
Search_Str := '';
Search_Lpos := 0;
Search_Line := 0;
WHILE( Command[Cind] <> Nul ) DO
BEGIN
Search_Str := Search_Str + Command[Cind];
Cind := Cind + 1;
END;
END;
END;
END
END
ELSE (* No initial number -- get command *)
BEGIN
c := Command[Cind];
Cind := Cind + 1;
SkipBl;
rel := ( Command[Cind] = NUL );
(* Trailing number = absolute positioning *)
IF c = '''' THEN (* Get search string *)
BEGIN
IF Command[Cind] <> Nul THEN
BEGIN
Search_Str := '';
Search_Line := 0;
Search_Lpos := 0;
WHILE( Command[Cind] <> Nul ) DO
BEGIN
Search_Str := Search_Str + Command[Cind];
Cind := Cind + 1;
END;
END;
END
ELSE
Number( n );
END;
(* Skip any trailing blanks *)
SkipBl;
(* If reached end of command string, *)
(* command is OK. *)
legal := Command[Cind] = nul;
(* execute positioning command if *)
(* it is legal. *)
IF legal THEN
CASE c OF
'L', 'l':
IF rel THEN
Find_Line( RMAX( top_line + n , 1.0 ) )
ELSE
Find_Line( RMAX( n , 1.0 ) );
'P', 'p':
IF rel THEN
Find_Page( RMAX( top^.pnum + n , 1.0 ) )
ELSE
Find_Page( RMAX( n , 1.0 ) );
'S', 's':
IF rel THEN
Find_Line( RMAX( top_line + Height * n , 1.0 ) )
ELSE
Find_Line( RMAX( Height * n - Height + 1.0 , 1.0 ) );
'C', 'c':
BEGIN
IF rel THEN
first_col := MAX( TRUNC( first_col + n ) , 1 )
ELSE
first_col := MAX( TRUNC( n ) , 1 );
IF lpt THEN first_col := MAX( first_col , 2 )
END;
'W', 'w':
BEGIN
ow := width;
IF rel THEN
width := MAX( width + TRUNC( n ) , 1 )
ELSE
width := MAX( TRUNC( n ) , 1 );
END;
'''':
BEGIN
GoToXY( WhereX + 1 , WhereY );
WRITE( '... Searching');
Find_Line( RMAX( Search_Line + 1 , Top^.Lnum ) );
Find_String( Search_Str );
END;
ELSE
legal := FALSE;
END;
END (* Position *);